use std::collections::HashMap;
use crate::{JaegerTracing, SidecarConfig, TcpClient};
use crate::bound::inbound::InBoundServer;
use crate::bound::outbound::OutBoundServer;
use crate::bound::{SidecarInBoundPort, TcpClientPort,SidecarOutBoundPort};
use crate::resource::resource::{Resource, ResourceString};

pub struct Sidecar {
    config:SidecarConfig,
    tcp_client:TcpClient,
    resource:HashMap<ResourceString,Vec<Resource>>,
    inbound:InBoundServer,
    outbound:OutBoundServer,
}

impl Sidecar {
    pub fn new(config:SidecarConfig) -> Self {
        let trace_endpoint = config.service_ip.clone();
        let server_name = config.service_name.clone();
        let trace = JaegerTracing::new(trace_endpoint.as_str(),server_name.as_str());

        let tcp_client = TcpClient::new(TcpClientPort as u32);

        let inbound = InBoundServer::new(SidecarInBoundPort,Some(trace));
        let outbound = OutBoundServer::new();

        let sidecar = Sidecar{
            config,
            tcp_client,
            resource: Default::default(),
            inbound,
            outbound
        };

        sidecar
    }
}